﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace SilentVoice.Models
{
    public partial class User : Auditable
    {
        public User()
        {
            this.Groups = new HashSet<Group>();
            this.ScratchPads = new HashSet<ScratchPad>();
            this.Events = new HashSet<Event>();
            this.MiddleName = "";
            this.Designation = "";
        }

        [Key]
        public int Id { get; set; }
        [Required]
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        [Required]
        public string LastName { get; set; }
        [Required]
        public string PasswordSalt { get; set; }
        [Required]
        public string PasswordHash { get; set; }
        [Required]
        public string Email { get; set; }
        public string Designation { get; set; }

       // [Required]
       // public virtual Account Account { get; set; }
        [Required(ErrorMessage="A user must belong to an account.")]
        public int AccountId { get; set; }
        public virtual ICollection<Group> Groups { get; set; }
        public virtual ICollection<ScratchPad> ScratchPads { get; set; }
        public virtual ICollection<Event> Events { get; set; }
        //[Required]
        //public virtual Role Role { get; set; }
        public int RoleId { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType().DeclaringType != this.GetType().DeclaringType)
            {
                System.Console.WriteLine("they're not the same type, {0} {1}", obj.GetType().DeclaringType.ToString(), this.GetType().DeclaringType.ToString());
                return false;
            }

            User other = (User)obj;

            return this.FirstName.Equals(other.FirstName)
                && this.MiddleName.Equals(other.MiddleName)
                && this.LastName.Equals(other.LastName)
                && this.Designation.Equals(other.Designation)
                && this.Email.Equals(other.Email);
        }

        public override int GetHashCode()
        {
            return String.Format("{0},{1},{2}", this.FirstName, this.MiddleName, this.LastName).GetHashCode();
        }
    }
}